    /********************************************************/
    /*                                                      */
    /*                                                      */
    /*         Copyright (C), 1993  SEIKO EPSON Corp.       */
    /*         ALL RIGHTS RESERVED                          */
    /*                                                      */
    /*                                                      */
    /*  file name : fwrite.c                                */
    /*                                                      */
    /*  Revision history                                    */
    /*      93/12/17    first release       S.Akaiwa        */
    /*      97/3/17	modified	    T.Katahira	    */
    /*			change function declaration	    */
    /*					to the ANSI style   */
    /*                                                      */
    /********************************************************/

#ifdef  UNIX
#include    "stdio.h"
#else
#include    <stdio.h>
#endif

size_t
fwrite(const void * vpBufP, size_t tdEleSiz, size_t tdEleCnt, FILE * fiStrmP)

    /********************************************************/
    /*                                                      */
    /*  The fwrite function writes data from the buffer     */
    /*  pointed to by vpBufP to stream pointed to by        */
    /*  fiStrmP.                                            */
    /*  If stdout or stderr is not specified by fiStrmP,    */
    /*  fwrite function returns 0.                          */
    /*  If write error is encountered, this function        */
    /*  returns number which may be less than tdEleCnt.     */
    /*  If 0 is specified by tdEleSiz or tdEleCnt, fwrite   */
    /*  function returns 0.                                 */
    /*                                                      */
    /*      RETURN  number of items actually write          */
    /*                                                      */
    /*  <ANSI>                                              */
    /*      The fwrite function writes data from the buffer */
    /*      to user specified stream.                       */
    /*                                                      */
    /*      RETURN  number of items actually write          */
    /*                                                      */
    /********************************************************/

    /* const void    *vpBufP     ;  pointer to write buffer */
    /* size_t  tdEleSiz    ;                   size of item */
    /* size_t  tdEleCnt    ; max count of items to be write */
    /* FILE    *fiStrmP    ;       pointer to target stream */
    {

     size_t tdWritCnt;                  /* write data count */
                                        
     if((fiStrmP != stdout) && (fiStrmP != stderr)){
        return  (int)0;                   /* illegal stream */
     }

     if((tdEleSiz == 0) || (tdEleCnt == 0)){
        return  (int)0;                 /* illegal argument */
     }

                                              /* write data */
     tdWritCnt = write(fiStrmP->_fd, (char *)vpBufP,
                                    tdEleSiz*tdEleCnt);

     return (int)(tdWritCnt/tdEleSiz); /* return write size */
    }

int write(int fd, char *buf, int nbytes)
{
	if (fd == stdout->_fd) {
		return os_stdout_write(buf, nbytes);
	}
	else if (fd == stderr->_fd) {
		return os_stderr_write(buf, nbytes);
	}
	else {
		return FileWrite(fd, buf, nbytes);
	}
}

